package com.bbx.flink.table_api_or_sql;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

/**
 * Flink   time attribute      processing time demo
 *Defining in DDL
 * The processing time attribute is defined as a computed column in
 * CREATE table DDL using the system PROCTIME() function.
 * Please see CREATE TABLE DDL for more information about computed column.
 */
public class TimeAttributeDDLProcessTimeDemo {
    public static void main(String[] args) {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);

        String createSql = "CREATE TABLE userActive (\n" +
                "id String,    \n" +
                "name String,  \n" +
                " user_action_time  as proctime()  \n"+
                ") WITH (      \n" +
                "  'connector.type' = 'jdbc',\n" +
                "  'connector.url' = 'jdbc:mysql://localhost:3306/flink_user?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC',\n" +
                "  'connector.table' = 'user_ac', \n" +
                "  'connector.driver' = 'com.mysql.cj.jdbc.Driver',\n" +
                "  'connector.username' = 'root',\n" +
                "  'connector.password' = '123456')" ;
        tableEnv.executeSql(createSql);

        String querySql = "select * from  userActive";
        tableEnv.executeSql(querySql).print();

    }



}
